import { Controller, Query, Body, Post, Get } from '@nestjs/common'
import { GetPhoneNumberDto, GetPhoneNumberQuery } from './dto/get-phone-number.dto'
import { GetCodeSessionDto } from './dto/get-code-session.dto'
import { ConfigService } from '@nestjs/config'
import { WxApiService } from './wx-api.service'
import { ApiTags } from '@nestjs/swagger'

@ApiTags('微信api')
@Controller('wx-api')
export class WxApiController {
  constructor(private readonly wxApiService: WxApiService, private readonly config: ConfigService) {}

  @Post('getPhoneNumber')
  async getPhoneNumber(@Body() dto: GetPhoneNumberDto) {
    return await this.wxApiService.getPhoneNumber(dto)
  }

  @Post('getCodeSession')
  async getCodeSession(@Body() dto: { js_code: string }) {
    let data: GetCodeSessionDto = {
      appid: this.config.get('APPID'),
      secret: this.config.get('SECRET'),
      grant_type: 'authorization_code',
      js_code: dto.js_code,
    }
    return await this.wxApiService.getCodeSession(data)
  }
}
